package com.qzimp.fujiancuo.controller;

import com.qzimp.fujiancuo.entity.Visitor;
import com.qzimp.fujiancuo.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/visitors")
public class VisitorController {

    @Autowired
    private VisitorService visitorService;

    // 添加访客
    @PostMapping("/add")
    public void addVisitor(@RequestBody Visitor visitor) {
        visitorService.addVisitor(visitor);
    }

    // 更新访客
    @PutMapping("/update")
    public void updateVisitor(@RequestBody Visitor visitor) {
        visitorService.updateVisitor(visitor);
    }

    // 删除访客
    @DeleteMapping("/delete/{visitorId}")
    public void deleteVisitor(@PathVariable Long visitorId) {
        visitorService.deleteVisitor(visitorId);
    }

    // 获取访客详情
    @GetMapping("/{visitorId}")
    public Visitor getVisitorById(@PathVariable Long visitorId) {
        return visitorService.getVisitorById(visitorId);
    }

    // 获取所有访客
    @GetMapping("/all")
    public List<Visitor> getAllVisitors() {
        return visitorService.getAllVisitors();
    }
}